////////////////////////////////////////////////////////////////////////////////
///
/// Example class that invokes native SoundTouch routines through the JNI
/// interface.
///
/// Author        : Copyright (c) Olli Parviainen
/// Author e-mail : oparviai 'at' iki.fi
/// WWW           : http://www.surina.net
///
////////////////////////////////////////////////////////////////////////////////

package net.surina.soundtouch;


public final class SoundTouch
{
    // Native interface function that returns SoundTouch version string.
    // This invokes the native c++ routine defined in "soundtouch-jni.cpp".
    public native final static String getVersionString();

    private native final void setTempo(long handle, float tempo);

    private native final void setPitchSemiTones(long handle, float pitch);
    
    private native final void setSpeed(long handle, float speed);

    private native final int processFile(long handle, String inputFile, String outputFile);

    private native final int processData(long handle, byte[] input, int byteNum, byte[] output, int byteMax, int channels);

    private native final void putBytes(long handle, byte[] input, int byteNum);

    private native final int getBytes(long handle, byte[] output, int byteMax);

    public native final static String getErrorString();

    private native final static long newInstance(long sampleRate, int channels);
    
    private native final void deleteInstance(long handle);
    
    long handle = 0;
    
    
    public SoundTouch(long sampleRate, int channels)
    {
    	handle = newInstance(sampleRate, channels);
    }
    
    
    public void close()
    {
    	deleteInstance(handle);
    	handle = 0;
    }


    public void setTempo(float tempo)
    {
    	setTempo(handle, tempo);
    }


    public void setPitchSemiTones(float pitch)
    {
    	setPitchSemiTones(handle, pitch);
    }

    
    public void setSpeed(float speed)
    {
    	setSpeed(handle, speed);
    }


    public int processFile(String inputFile, String outputFile)
    {
    	return processFile(handle, inputFile, outputFile);
    }

    public int processData(byte[] input, int byteNum, byte[] output, int byteMax, int channels) {
        return this.processData(handle, input, byteNum, output, byteMax, channels);
    }

    public void putBytes(byte[] input, int byteNum) {
        putBytes(handle, input, byteNum);
    }

    public int getBytes(byte[] output, int byteMax) {
        return getBytes(handle, output, byteMax);
    }

    // Load the native library upon startup
    static
    {
        System.loadLibrary("soundtouch");
    }
}
